<?php
/**
 * 约课评价表
 */

class Book_evaluate_model extends CT_Model{
    
    public $_table = 'book_evaluate';
    
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
	}
	/**
	 * 获取评价列表
	 */
	public function evaluate_list($conditions = NULL, $fields = '*', $order = NULL, $start = 0, $limit = NULL){
	    try {
	        if ($fields != NULL) {
	            $this->db->select ( $fields );
	        }
	        $this->db->from($this->_table);
	        $this->db->join('course_package',"course_package.id = {$this->_table}.course_package_id", 'join');
	        $this->db->join('course_list','course_list.id = course_package.course_list_id', 'join');
	        $this->db->join('course_cate','course_cate.id = course_list.course_cate_id', 'join');
	        $this->db->join('nursery','nursery.id = course_cate.nursery_id', 'join');
// 	        $this->db->join('member',"member.id = {$this->_table}.member_id", 'join');
	        
	        if ($conditions != NULL && $conditions) {
	            if (is_array ( $conditions )) {
	                $this->db->where ( $conditions );
	            } else {
	                $this->db->where ( $conditions, NULL, FALSE );
	            }
	        }
	         
	        
	        if ($order != NULL) {
	            $this->db->order_by ( $order );
	        }
	        
	        if ($limit != NULL) {
	            $this->db->limit ( $limit, $start );
	        }
	        
	        return $this->db->get()->result_array();
	        
	        
	    }catch (Exception $e){
	        
	    }
	}
	
	
	/**
	 * 获取评价列表数
	 */
	public function evaluate_count($conditions = NULL){
	        
        $this->db->from($this->_table);
        $this->db->join('book',"book.id = {$this->_table}.book_id", 'left');
         
        if ($conditions != NULL && $conditions) {
            if (is_array ( $conditions )) {
                $this->db->where ( $conditions );
            } else {
                $this->db->where ( $conditions, NULL, FALSE );
            }
        }
         
        return $this->db->count_all_results();
	    
	}
}
